{include file="public/header" /}
<body class="bgc">
<div class="header">
    <span class="layui-icon layui-icon-left" onclick="load_href('{:url(\'user/index\')}',2)"></span> 我的交易
</div>

<ul class="pro-list-nav-top">
    <li data-type="1" class="{if $Request.param.type == 1 ||  !$Request.param.type}active{/if}">
        <div>买单</div>
        <p></p>
    </li>
    <li data-type="2" class="{if $Request.param.type == 2}active{/if}">
        <div>卖单</div>
        <p></p>
    </li>
</ul>
<ul class="pro-list-nav">
    <li data-status="1" class="{if $Request.param.status == 1 || !$Request.param.status}active{/if}">
        <div>待支付</div>
        <p></p>
    </li>
    <li data-status="2" class="{if $Request.param.status == 2}active{/if}">
        <div>待收款</div>
        <p></p>
    </li>
    <li data-status="3" class="{if $Request.param.status == 3}active{/if}">
        <div>已完成</div>
        <p></p>
    </li>
    <li data-status="4" class="{if $Request.param.status == 4}active{/if}">
        <div>已撤销</div>
        <p></p>
    </li>
</ul>

<ul class="my-order-list tpl_list">

</ul>
<script id="template" type="text/html">


    {{# for(var i=0;i < d.data.length ;i++){ }}
    <li>
        <p class="flex-layout">{{d.data[i].type == 1 ?'卖家：'+d.data[i].user.code+'-'+d.data[i].user.nickname+(d.data[i].user.mobile?'-'+d.data[i].user.mobile:''):'买家：'+d.data[i].buser.code+'-'+d.data[i].buser.nickname+(d.data[i].buser.mobile?'-'+d.data[i].buser.mobile:'')}}<span>{{d.data[i].statusText}}</span></p>
        <div class="b flex-layout" style="height: 1.5rem !important;">
            <div class="time">交易时间：{{d.data[i].create_time}}</div>
        </div>
        <div class="b flex-layout" style="height: 1.5rem !important;">
            <div class="time">单价：{{d.data[i].price}}</div>
            <div class="time">数量：{{d.data[i].num}}</div>
            <div class="time">总价：{{d.data[i].money}}</div>
        </div>
        {{# if(d.data[i].types == 2){ }}
            {{# if(d.data[i].status == 2 || d.data[i].status == 3){ }}
            <div class="flex-layout" style="height: 1.5rem !important;">
                <div>付款方式：{{d.data[i].pay_way}}</div>
            </div>
            <div class="flex-layout" style="height: 1.5rem !important;">
                <a href="javascript:;" style="color: var(--bc) !important;" class="openShowImg" data-value="{{d.data[i].images}}">查看付款截图</a>
            </div>
            {{# } }}
        {{# } }}
        <div class="order-btn">
            <a href="javascript:;" data-id="{{d.data[i].id}}" class="details">交易详情</a>
            {{# if(d.data[i].types == 1){ }}
                {{# if(d.data[i].status == 1){ }}
                    <!-- <a href="javascript:;" class="clearOrder" data-id="{{d.data[i].id}}">撤销订单</a> -->
                    <a href="{:url('deal/payment')}?id={{d.data[i].id}}" class="bc">立即付款</a>
                {{# } }}
            {{# }else { }}
                {{# if(d.data[i].status == 2){ }}
                    <a href="javascript:;" data-id="{{d.data[i].id}}" class="bc receipt">确认收款</a>
                {{# } }}
            {{# } }}

        </div>
    </li>
    {{# } }}

</script>
</body>
{include file="public/footer"/}
<script>
    $(function () {
        getFlowList('{$Request.param.type?:1}','{$Request.param.status?:1}', "{:url('deal/getDealList')}");
        $('.pro-list-nav-top li').click(function () {
            $(this).addClass('active').siblings().removeClass('active');
            getDealList($(this).attr('data-type'),$(".pro-list-nav .active").attr('data-status'));
        });
        $('.pro-list-nav li').click(function () {
            $(this).addClass('active').siblings().removeClass('active');
            getDealList($(".pro-list-nav-top .active").attr('data-type'),$(this).attr('data-status'));
        });
        function getDealList(type,status){
            $(".tpl_list").empty();
            getFlowList(type,status, "{:url('deal/getDealList')}");
        }
        $('.tpl_list').on('click', '.clearOrder', function () {
            const id = $(this).attr('data-id');
            edit('clear', id, '确认要撤销订单吗？')
        }).on('click', '.receipt', function () {
            const id = $(this).attr('data-id');
            edit('receipt', id, '是否确认收款？')
        }).on('click', '.details', function () {    
            console.log($(".pro-list-nav .active").attr('data-status'));
            window.location.href = "{:url('deal/my_deal_info')}?id="+$(this).attr('data-id')+'&type='+$(".pro-list-nav-top .active").attr('data-type')+'&status='+$(".pro-list-nav .active").attr('data-status');
        });

        function edit(type, id, msg) {
            layer.confirm(msg, {title: '请确认'}, function () {
                common.load()
                $.ajax({
                    type: 'POST',
                    url: '{:url("deal/edit")}',
                    data: {type: type, id: id},
                    dataType: "json",
                    success: function (data) {
                        layer.closeAll;
                        layer.msg(data.msg);
                        if (data.code == 1) {
                            window.location.href = data.url;
                        }
                    }
                });
            });
        }
    })
</script>
</html>